package model;

import java.io.Serializable;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import beans.MestoBean;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class Mesto implements Serializable {

	private static final long serialVersionUID = 50800974255852026L;

	// public static Double version;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key sifra;

	private String naziv;
	
	//geografska sirina i duzina
	private double duzina;
	private double sirina;

	public Mesto() {
		super();
	}

	public Mesto(String naziv) {
		super();
		this.naziv = naziv;
		this.duzina = 0;
		this.sirina = 0;
	}

	public Mesto(Key sifra, String naziv) {
		super();
		this.sifra = sifra;
		this.naziv = naziv;
		this.duzina = 0;
		this.sirina = 0;
	}
	
	public Mesto(Key sifra, String naziv, double duzina, double sirina) {
		super();
		this.sifra = sifra;
		this.naziv = naziv;
		this.duzina = duzina;
		this.sirina = sirina;
	}
	
	public Mesto(MestoBean mesto) {
		super();
		this.naziv = mesto.getNaziv();
	}

	public Key getSifra() {
		return sifra;
	}

	public void setSifra(Key sifra) {
		this.sifra = sifra;
	}

	public String getNaziv() {
		return naziv;
	}

	public void setNaziv(String naziv) {
		this.naziv = naziv;
	}
	
	public double getDuzina() {
		return duzina;
	}

	public void setDuzina(double duzina) {
		this.duzina = duzina;
	}

	public double getSirina() {
		return sirina;
	}

	public void setSirina(double sirina) {
		this.sirina = sirina;
	}

	public MestoBean toBMestoBean() {
		return new MestoBean(Integer.valueOf((int) sifra.getId()), naziv,
				Double.valueOf(duzina),Double.valueOf(sirina));
	}

	@Override
	public String toString() {
		return "Mesto; sifra: " + sifra + ", naziv: " + naziv 
				+ " , duzina: " + duzina + " , sirina: " + sirina;
	}
}